package com.shop2cn.iapi.sqoptrade.testcase;

import java.math.BigDecimal;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.shenqisettlement.parameter.bean.AgentProductBean;
import com.shop2cn.iapi.sqoptrade.parameter.req.OrderPurchaserAndOrderPayerIsConsistentReq;
import com.shop2cn.iapi.sqoptrade.resp.TradingServiceResp;
import com.shop2cn.iapi.sqoptrade.service.OrderPurchaserAndOrderPayerIsConsistentCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.SQPayGateWayCallService;
import com.ymttest.business.service.shenqi.DGSQBuildProxyChainCallService;
import com.ymttest.business.service.shenqi.SqTradingCallService;
import com.ymttest.utils.EnvSetup;

public class Ts_SqOrderPurchaserAndOrderPayerIsConsistent {

	private static OrderPurchaserAndOrderPayerIsConsistentReq orderPurchaserAndOrderPayerIsConsistentReq;
	private static OrderPurchaserAndOrderPayerIsConsistentCall orderPurchaserAndOrderPayerIsConsistentCall;
	private static long autotest_goodsOwnerId = Long.valueOf(EnvSetup
			.getData("autotest_goodsOwnerId"));
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("推单接口");
	}

	@Before
	public void caseUp() {
		orderPurchaserAndOrderPayerIsConsistentReq = new OrderPurchaserAndOrderPayerIsConsistentReq();
		orderPurchaserAndOrderPayerIsConsistentCall = new OrderPurchaserAndOrderPayerIsConsistentCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(orderPurchaserAndOrderPayerIsConsistentCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	public static void verify(long orderId) {
		
		
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_OrderPurchaserAndOrderPayerIsConsistent_001() {
		Logger.start(true, "推单接口");
		try {
			
			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);

			TradingServiceResp resp = SqTradingCallService
					.placeOrderWithPurchaserIdcardId(productBean,
							20238699L);
			
			Long userId = resp.getUserId();
			long mainOrderId = resp.getMainOrderId();
			BigDecimal totalPrice = resp.getPayableAmount();
			
			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					resp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(),
					productBean.getCurrency());

			Thread.sleep(5000);
			
			orderPurchaserAndOrderPayerIsConsistentReq.setUserId(userId);
			orderPurchaserAndOrderPayerIsConsistentReq.setMainOrderId(mainOrderId);
			
			orderPurchaserAndOrderPayerIsConsistentCall.setData(orderPurchaserAndOrderPayerIsConsistentReq);
			orderPurchaserAndOrderPayerIsConsistentCall.callService();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
